#include "RsGisLibSegRandColourClumps.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibSegRandColourClumps::RsGisLibSegRandColourClumps(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibSegRandColourClumps();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_ImportLUTFile, SIGNAL(clicked()), this, SLOT(on_action_Button_ImportLUTPath_clicked()));
	connect(ui->pushButton_ExportLUTFile, SIGNAL(clicked()), this, SLOT(on_action_Button_ExportLUTPath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_Execute, SIGNAL(clicked()), this, SLOT(on_action_Button_Execute_clicked()));

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_ImportLUTFile->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_ExportLUTFile->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\Out");

	QStringList FlagList;
	FlagList.append("False");
	FlagList.append("True");
	ui->comboBox_InMemory->addItems(FlagList);
	ui->comboBox_ImportLUT->addItems(FlagList);
	ui->comboBox_ExportLUT->addItems(FlagList);

	ui->lineEdit_GdalFormat->setText("GIFF");
	ui->comboBox_InMemory->setCurrentIndex(0);
	ui->comboBox_ImportLUT->setCurrentIndex(0);
	ui->comboBox_ExportLUT->setCurrentIndex(0);

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibSegRandColourClumps::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibSegRandColourClumps::on_action_Button_ImportLUTPath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_ImportLUTFile->setText(str.toUtf8());
}

void RsGisLibSegRandColourClumps::on_action_Button_ExportLUTPath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_ExportLUTFile->setText(str.toUtf8());
}

void RsGisLibSegRandColourClumps::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibSegRandColourClumps::on_action_Button_Execute_clicked()
{
	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("Segmentation"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("RandColourClumps"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));
	AlgParaList << QVariant(int(ui->comboBox_InMemory->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_ImportLUTFile->text()));
	AlgParaList << QVariant(int(ui->comboBox_ImportLUT->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_ExportLUTFile->text()));
	AlgParaList << QVariant(int(ui->comboBox_ExportLUT->currentIndex()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}